// pages/index/party/party.js
const app = getApp()
//获取 log 日志打印
const log = new app.appLogs()
//获取 http 网络请求
const http = new app.appHttp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        isbt: '',
        isbt2: '',
        organizationlist: [],
        governmentlist: [],
        policylist: [],
        worklist: [],
        problemlist: [],
        isLoading: true
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.setData({
            theme: app.globalData.theme
        })
        this.onOrganization()
        this.getOrganization()
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {
        log.e('下拉')
    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {
        log.e('上拉')
    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    },
    /**
     * 当前激活的标签改变时触发
     * @param event
     */
    onChange(event) {
        const than = this
        const num = event.detail.name
        if (num == 0) {
            than.onOrganization()
            than.getOrganization()
        } else if (num == 1) {
            than.onPolicy()
            than.getPolicy()
        }
    },
    /**
     * 党组织按钮
     * @param event
     */
    onOrganization: function (event) {
        const than = this
        //判断按钮状态
        than.getOrganization()
        than.setData({
            isbt: '0'
        })

    },
    /**
     * 党务政务按钮
     * @param event
     */
    onGovernment: function (event) {
        const than = this
        //判断按钮状态
        than.getGovernment()
        than.setData({
            isbt: '1'
        })
    },
    /**
     * 党组织详情
     * @param event
     */
    onOrganizationDetails: function (event) {
        const id = event.currentTarget.dataset.id
        log.e("党组织id：" + id)
        wx.navigateTo({
            url: '../party/partydetails/partydetails?id=' + id
        })
    },
    /**
     * 党建活动详情
     * @param event
     */
    onGovernmentDetails: function (event) {
        const id = event.currentTarget.dataset.id
        log.e("党建活动id：" + id)
        wx.navigateTo({
            url: '../party/partyactivitydetails/partyactivitydetails?id=' + id
        })
    },
    /**
     * 政策法规按钮
     * @param event
     */
    onPolicy: function (event) {
        const than = this
        than.getPolicy()
        //判断按钮状态
        than.setData({
            isbt2: '0'
        })
    },
    /**
     * 办事指南按钮
     * @param event
     */
    onGuide: function (event) {
        const than = this
        than.getGuide()
        //判断按钮状态
        than.setData({
            isbt2: '1'
        })
    },
    /**
     * 常见问题按钮
     * @param event
     */
    onProblem: function (event) {
        const than = this
        than.getProblem()
        //判断按钮状态
        than.setData({
            isbt2: '2'
        })
    },
    /**
     * 请求党组织列表
     * @param event
     */
    getOrganization: function (event) {
        const than = this
        this.setData({
            isLoading: true
        })
        http.get("party/getPartyOrgList", {
            area_code: app.globalData.areaCode
        }).then((res) => {
            if (res.data.code == 200) {
                than.setData({
                    organizationlist: res.data.data
                })
            }
            this.setData({
                isLoading: false
            })
        })
    },
    /**
     * 请求党建活动列表
     * @param event
     */
    getGovernment: function (event) {
        const than = this
        http.get("party/getPartyOrgActivityList", {
            area_code: app.globalData.areaCode
        }).then((res) => {
            if (res.data.code == 200) {
                than.setData({
                    governmentlist: res.data.data
                })
            }
        })
    },
    /**
     * 请求政策法规列表  5
     * @param event
     */
    getPolicy: function (event) {
        const than = this
        http.get("notice/list", {
            type: "5",
            applet_id: app.globalData.applet.applet_id,
            unit_code: app.globalData.unitCode,
        }).then((res) => {
            if (res.data.code == 200) {
                than.setData({
                    policylist: res.data.data
                })
            }
        })
    },
    /**
     * 请求办事指南列表  6
     * @param event
     */
    getGuide: function (event) {
        const than = this
        http.get("notice/list", {
            type: "6",
            applet_id: app.globalData.applet.applet_id,
            unit_code: app.globalData.unitCode,
        }).then((res) => {
            if (res.data.code == 200) {
                than.setData({
                    worklist: res.data.data
                })
            }
        })
    },
    /**
     * 请求常见问题列表  7
     * @param event
     */
    getProblem: function (event) {
        const than = this
        http.get("notice/list", {
            type: "7",
            applet_id: app.globalData.applet.applet_id,
            unit_code: app.globalData.unitCode,
        }).then((res) => {
            if (res.data.code == 200) {
                than.setData({

                    problemlist: res.data.data
                })
            }
        })
    },
    /**
     * 详情界面
     * @param event
     */
    onDetails: function (event) {
        const id = event.currentTarget.dataset.id
        const content_id = event.currentTarget.dataset.content_id
        wx.navigateTo({
            url: '../notice/notice?id=' + id+"&content_id="+content_id
        })
    }
})